<!--兑换记录-->
<template>
  <div class="all bg1">
    <template v-if="datas">
      <VTips v-if="!datas.length"></VTips>
      <list class="list" :loadmoreoffset="50" @loadmore="httpsRecordLoading">
        <!--刷新-->
        <refresh @refresh="httpsRecords" :display="isRefresh ? 'show' : 'hide'">
          <loading-indicator class="load text1"></loading-indicator>
        </refresh>

        <cell v-for="(item, index) in datas" v-bind:key="index">

          <div class="cell bg2" @click="infoClick(item)">
            <div class="row acenter">
              <text class="font32 text2 all">{{"+ "+item.toNumber+" "+item.toCoin}}</text>
              <div class="width20"></div>
              <text class="font30 text3">{{T('普通兑换')}}</text>
            </div>

            <div class="height10"></div>
            <div class="row acenter">
              <text class="font24 text3 all">{{item.createTime}}</text>
              <div class="width20"></div>
              <text class="font24 text2">{{T('成功')}}</text>  
              <LImage class="img-arrow" :src="Config.img('jiantou_lan.png')"></LImage> 
            </div>
          </div>

          <!-- 无更多数据 -->
          <div class="genduo" v-if="pageMax && (index == datas.length - 1)">
            <text class="font22 text3">{{T('没有更多数据')}}</text>
          </div>
        </cell>
      </list>
    </template>
  </div>
</template>

<style src="@/_css/style.css" ></style>
<style scoped>
.list {
  flex: 1;
  margin-top: 10px;
  padding-left: 20px;
  padding-right: 20px;
}
.cell {
  border-radius: 24px;
  padding: 30px;

  margin-top: 20px;
}
.img-arrow {
  width: 8px;
  height: 13px;
  margin-left: 10px;
}

/*************************** 加载更多*/
.load {
  height: 40px;
  width: 40px;

  margin-top: 20px;
  margin-left: 355px;
}
.genduo {
  flex-direction: row;
  justify-content: center;
  align-items: center;
  width: 750px;
  height: 100px;
}
</style>

<script>
//组件
import VTips from '@/_public/VTips.vue';  //标题

//功能
import jnavigator from "@/_js/navigator";
import jmodal from "@/_js/modal";
import jmath from "@/_js/math";
import jhttps from "@/_js/https";
import jtime from "@/_js/time";
import jconfig from "@/_js/config";

const weexFunction = weex.requireModule("WeexFunction");

import I18N from "@/_i18n/i18n";
var T = I18N.t;
weexFunction.setTitle(T('兑换记录'));

export default {
  
  components: {
    VTips,
  },

  data() {
    return {
      T:T,
      Config:jconfig,
      wallet:undefined, //consumeWallet(消费钱包) incomeWallet(收益钱包) depositWallet(保证金钱包)


      datas:undefined, //数据源

      pageNo:0, //页码
      pageMax:false, //turn最大页面
      isRefresh:false, //显示刷新
      isLoadinging:false, //显示加载
    };
  },

  created() {

    var param = weex.config;
    this.wallet = param.wallet;

    this.httpsRecords();
  },

  methods: {
  
    initData(datas) {
      for (let index = 0; index < datas.length; index++) {
        var data = datas[index];
        data.createTime = jtime.getTime(data.createTime, 'y/M/d H:m');
      }
      return datas;
    },

    /********************************* HTTP*/
    //http记录-刷新
    httpsRecords() {
      if (this.isRefresh || this.isLoadinging) return;
      this.isRefresh = true;

      var params = {'pageNo':1,
                    'wallet':this.wallet};
      jhttps.post("wallet/queryConvertRecodeList",params,true,(data)=>{
        this.isRefresh = false;
        if (data.status == 200) {
          data = data.data;

          this.datas = this.initData(data);
          this.pageNo = 1;
          this.pageMax = this.datas.length < 20;
        } else {
          jmodal.toast(data.msg);
        }
      });
    },

    //http记录-加载
    httpsRecordLoading() {
      if (this.pageMax || this.isRefresh || this.isLoadinging) return;
      this.isLoadinging = true;

      var params = {'pageNo':this.pageNo+1, 
                    'wallet':this.wallet};
      jhttps.post("wallet/queryConvertRecodeList",params,true,(data) => {
        this.isLoadinging = false;
        if (data.status == 200) {
          data = data.data;
          var datas = this.initData(data);
          this.datas.push(...datas);
          this.pageNo++;
          this.pageMax = datas.length < 20;
        } else {
          jmodal.toast(data.msg);
        }
      });
    },

    /********************************* 点击*/
    //详情信息
    infoClick(item){
      var nav = {'navColor':'#0c0c0c'};
      var param = {'orderId':item.orderId}
      jnavigator.open("", "wallet/WalletDhInfo", param, nav);
    },
  }
};
</script>
